<?php

use app\models\Mall;
use yii\helpers\Url;

$web = Url::base();
//单位
$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$institution_code=Mall::getCurrentInstitutionCode();
$this->title = $site_name . '-支付结果';
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/pay-success.css" />
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/await-pay.css" />
<div class="main">
    <div class="heade">
        <div class="hint">
            <img src="<?= $web ?>/images/mall-m/pay-success.png"/>
            <div class="hint-content">
                <p class="success">支付成功</p>
                <p class="contener">您的订单会尽快进行处理</p>
            </div>
        </div>
        <div class="btn">
            <a href="<?=Url::to(['mall-m/index','institution_code'=>$institution_code])?>" class="go-home">回到首页</a>
            <a href="<?=Url::to(['mall-m/order-list','institution_code'=>$institution_code])?>" class=" continue-shopping">订单列表</a>
        </div>
    </div>
    <div class="content">
        <p>交易方式：<span><?=$isMix=='1'?'混合支付':'积分支付' ?></span></p>
        <p>订单编号：<span><?=$orderInfo['code']?></span></p>
        <p><a href="<?=Url::to(['mall-m/order-detail','institution_code'=>$institution_code,'orderCode'=>$orderInfo['code']])?>">（点击查看订单详情）</a></p>
        <p>下单时间：<span><?=$orderInfo['modify_datetime']?></span></p>
        <p>支付积分：<span class="sum"><?=intval($orderInfo['integral'])?><?=$integral_unit?></span></p>
        <?php
            if($isMix=='1'){
        ?>
           <p>支付现金：<span class="sum"><?=($orderInfo['total_fee'])?>￥</span></p>
        <?php
            }
        ?>

    </div>
<!--    <input type="button" value="test" onclick="testOrder();">-->
</div>
<div class="await-window" style="display: none;">
    <div class="window-content">
        <img src="<?= $web ?>/images/mall-m/await-ing.png"/>
        <p>等待支付完成</p>
    </div>
    <div class="shade"></div>
</div>
<script>
    testOrder=function(){

        var reMix=requestJsonMallM('test-order-handle',{orderCode:"<?=$orderInfo['code']?>"});
    };

    var isMix=<?=$isMix?>;
    var order_status=<?=$orderInfo['status']?>;
    $(function($){
        var isEnd=getUrlParamValue(window.location.href,'isEnd');
        if(isMix==1 && order_status==1 && isEnd!='yes'){
            $('.success').html('正在等待支付完成');
            $('.contener').hide();
            $('.hint img').hide();
            $('.await-window').show();
            isWattingGetPayCash=true;
            getPayCash();
        }else{
           //normal
        }
    });
//    查询现金支付记录
    var out_trade_no='<?=$out_trade_no?>';
    var isWattingGetPayCash=false;
    var watting_num=0;
    getPayCash=function(){
        if(isWattingGetPayCash==false){
            return;
        }
        if(watting_num>20){
            $('.success').html('支付失败，请联系客服!');
            alert('支付失败，请联系客服!');
            window.location.href="order-detail?orderCode=<?=$orderInfo['code']?>";
            return;
        }
        watting_num++;
        isWattingGetPayCash=false;
        var data={};
        data.out_trade_no=out_trade_no;
        var reMix=requestJsonMallM('get-pay-integral-record-handle',data,true,function(re){
            if(re.status!=0){

                alert(re.message);
            }else{
                if(re.data.cash_status==1){
                    //支付完成,避免回退不停刷新
                    var url=window.location.href;
                    url=setUrlParam(url,'isEnd','yes');
                    window.location.href=url;
                }else {
                    isWattingGetPayCash = true;
                    setTimeout('getPayCash()',1000);
                }
            }
        });
    };

</script>
